package ar.edu.unlu.sistemas.ws.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ar.edu.unlu.sistemas.ws.test.ResultsLogProcessor.DocumentRow;
import ar.edu.unlu.sistemas.ws.test.ResultsLogProcessor.QueryResults;

public class LemurQueryResultsProcessor {
	
	private static String current = QueriesLogProcessor.GRULIC_RR;
	private static QueryResults[] query_results = new QueryResults[800];
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Matcher m;
		String line;
		Integer id;
		String docName;
		Integer index;
		Double rank;
		Pattern pattern = Pattern.compile("(\\d+)\\s[\\d\\w]+\\s(\\/.+)*\\/(.+\\.txt)\\s(\\d+)\\s(\\d+\\.\\d+)\\sindri.*");
		BufferedReader br = new BufferedReader(new FileReader(new File("/home/pepo/Dropbox/Tesis/lemur/bin/lemur_query_results_"+current.toUpperCase())));
		while((line = br.readLine())!=null) {
			if ((m=pattern.matcher(line)).matches()) {
				id =  new Integer(m.group(1));
				if (query_results[id]==null) query_results[id] = new QueryResults(null, id);
				docName = m.group(3);
				index = new Integer(m.group(4));
				rank = new Double(m.group(5));
				query_results[id].documents.add(new DocumentRow(docName, rank, "lemur"));
			}
		}
		br.close();
		
		System.out.println("\n// RESULTADOS DE LAS QUERIES //");
		for (QueryResults qr : query_results) {
			if (qr!=null)System.out.println(qr.toString());
		}
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("/home/pepo/Dropbox/Tesis/Resultados/"+current.toUpperCase()+"_lemur_result_object")));
		oos.writeObject(query_results);
		oos.close();

	}

}
